import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/pages/device/widgets/device_header.dart";
import "package:ct_pa_majordomo/widgets/button/index.dart";
import "package:ct_pa_majordomo/widgets/divider/solid_divider.dart";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";

class SelectRooms extends StatefulWidget {
  const SelectRooms({super.key});

  @override
  State<StatefulWidget> createState() => _SelectRoomsState();

}

class _SelectRoomsState extends State<SelectRooms> {

  final List _list = [{"name": "A103", "value": false}, {"name": "A107", "value": false}];

  bool _canSave() {
   return _list.any((item) => item["value"]);
  }

  @override
  Widget build(BuildContext context) {
    return DeviceHeader(
      title: "关联公区房间",
      leading: IconButton(
        icon: const Icon(Icons.arrow_back_ios_new),
        onPressed: () {
          Navigator.pop(context);
        },
      ),
      showSearch: false,
      showFloatBtn: false,
      children: [
        Container(
          padding: const EdgeInsets.only(top: 60, bottom: 78),
          child: ListView.separated(
              itemBuilder: (context, index) {
                return GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () => setState(() {
                    _list[index]["value"] = !_list[index]["value"];
                  }),
                  child: Container(
                    padding: const EdgeInsets.fromLTRB(ThemeVars.paddingPage, 4, 0, 4),
                    decoration: const BoxDecoration(
                      color: Colors.white,
                    ),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text("sss"),
                        CupertinoCheckbox(
                          value: _list[index]["value"],
                          onChanged: (value) => setState(() {
                            _list[index]["value"] = value;
                          })
                        )
                      ],
                    ),
                  ),
                );
              },
              separatorBuilder: (context, index) => const SolidDivider(padding: EdgeInsets.only(left: 12)),
              itemCount: _list.length
          ),
        ),
        Positioned(
            width: MediaQuery.of(context).size.width,
            top: 0,
            left: 0,
            child: Container(
                width: MediaQuery.of(context).size.width,
                decoration: const BoxDecoration(
                  color: ThemeVars.colorBackground,
                ),
                child: Column(
                  children: [
                    Container(
                      padding: const EdgeInsets.symmetric(horizontal: ThemeVars.paddingPage, vertical: 6),
                      decoration: const BoxDecoration(
                          color: Colors.white
                      ),
                      child: const SizedBox(
                        height: 40,
                        child: TextField(
                          decoration: InputDecoration(
                            border: OutlineInputBorder(
                                borderRadius: BorderRadius.all(Radius.circular(5)),
                                borderSide: BorderSide.none
                            ),
                            hintText: "请输入",
                            isDense: true,
                            filled: true,
                            fillColor: ThemeVars.colorBackground,
                            suffixIcon: SizedBox(
                              child: Icon(Icons.search, size: 20,),
                            ),
                          ),
                          style: TextStyle(fontSize: 14),
                        ),
                      ),
                    ),
                    const SizedBox(height: 10, child: DecoratedBox(decoration: BoxDecoration(color: ThemeVars.colorBackground)),)
                  ],
                )
            )
        ),
        Positioned(
            bottom: 0,
            left: 0,
            width: MediaQuery.of(context).size.width,
            child: Container(
              padding: const EdgeInsets.symmetric(horizontal: ThemeVars.paddingPage, vertical: 16),
              decoration: const BoxDecoration(
                  color: Colors.white,
                  boxShadow: [ThemeVars.boxShadow]
              ),
              child: Button(
                type: ButtonType.primary,
                onPressed: _canSave()
                  ? () {}
                  : null,
                child: const Text("保存")
              ),
            )
        ),
      ],
    );
  }

}